package com.estate.web.controller.eastate;

import com.alibaba.fastjson.JSONObject;
import com.estate.common.core.controller.BaseController;
import com.estate.common.core.domain.AjaxResult;
import com.estate.common.core.domain.entity.SysBuy;
import com.estate.common.core.page.TableDataInfo;
import com.estate.system.mapper.SysBuyMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/estate")
public class EstateController extends BaseController {

    @Resource
    SysBuyMapper sysBuyMapper;

    /*
    * 跳转到buy页面
    * */
    @GetMapping("/buy")
    public String toBuy(){

        return "/estate/buy";
    }

    @PostMapping("/selectBuy")
    @ResponseBody
    public TableDataInfo selectBuy(SysBuy sysBuy){
        startPage();
        JSONObject object = JSONObject
                .parseObject("{\"total\":1,\"rows\":[{\"searchValue\":null,\"createBy\":null,\"createTime\":null,\"updateBy\":null,\"updateTime\":null,\"remark\":null,\"params\":{},\"id\":1,\"title\":\"0\",\"buy_detail_id\":0,\"imgAddress\":\"0\",\"typeHouse_area\":\"0\",\"advantages\":\"0\",\"if_need_show\":1,\"price\":0}],\"code\":0,\"msg\":null}");

        List<SysBuy> list = sysBuyMapper.selectBuyList(sysBuy);
        return getDataTable(list);
    }
    @GetMapping("/add")
    public String add()
    {
        return"estate/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysBuy sysBuy)
    {

        return toAjax(sysBuyMapper.insertBuy(sysBuy));

    }





}
